#!/usr/bin/env node
/* This is a super hacky bit of code that takes a specially formatted SVG file
and creates an Espruino vector font from it.

*/

// SVG contents from http://forum.espruino.com/conversations/347368/#comment15288563 (fontmap_13x19.svg in thie directory)
// Converted with https://nebbishhacker.github.io/svg2bangle/ tolerance 0
var polyImg = [
  {fill: "#000000", points: [96,129,95,130,94,130,92,129,91,130,92,131,94,132,95,132,97,131,98,129,98,121,96,121]},
  {fill: "#000000", points: [43,193,41,194,40,196,40,201,39,203,39,205,47,205,47,203,41,203,42,201,42,196,43,195,44,195,45,196,47,195,46,194,44,193]},
  {fill: "#000000", points: [32,63,32,64,31,65,27,68,26,70,26,72,34,72,34,70,28,70,28,71,29,69,33,66,34,64,34,63]},
  {fill: "#000000", points: [26,79,26,91,28,91,28,81,31,81,32,82,32,83,31,84,28,84,28,86,32,86,33,87,33,88,32,89,28,89,28,91,32,91,34,90,35,88,35,87,34,85,32,84,33,85,34,83,34,82,33,80,31,79]},
  {fill: "#000000", points: [52,79,52,91,54,91,54,81,56,81,58,82,59,84,59,86,58,88,56,89,54,89,54,91,57,91,59,90,60,89,61,87,61,83,60,81,59,80,57,79]},
  {fill: "#000000", points: [73,91,73,89,67,89,67,86,71,86,71,84,67,84,67,81,73,81,73,79,65,79,65,91]},
  {fill: "#000000", points: [78,79,78,91,80,91,80,86,84,86,84,84,80,84,80,81,86,81,86,79]},
  {fill: "#000000", points: [17,79,13,91,15,91,18,82,20,86,16,86,15,88,21,88,18,82,21,91,23,91,19,79]},
  {fill: "#000000", points: [18,129,20,129,20,121,18,121]},
  {fill: "#000000", points: [42,121,40,122,39,124,39,126,40,128,42,129,43,129,45,128,46,126,44,126,43,127,42,127,41,126,41,124,42,123,43,123,44,124,46,124,45,122,43,121]},
  {fill: "#000000", points: [68,121,66,122,65,124,65,126,66,128,68,129,69,129,71,128,70,127,68,127,67,126,67,124,68,123,69,123,70,124,67,124,67,126,72,126,72,124,71,122,69,121]},
  {fill: "#000000", points: [79,129,79,120,80,118,82,117,83,117,83,119,82,119,81,120,81,129]},
  {fill: "#000000", points: [198,121,196,122,195,124,195,126,196,128,198,129,199,129,199,127,198,127,197,126,197,124,198,123,199,123,200,124,200,126,199,127,199,129,201,128,202,126,202,124,201,122,199,121]},
  {fill: "#000000", points: [104,79,104,91,106,91,106,86,111,86,111,91,113,91,113,79,111,79,111,84,106,84,106,79]},
  {fill: "#000000", points: [117,79,117,81,118,81,118,89,117,89,117,91,121,91,121,89,120,89,120,81,121,81,121,79]},
  {fill: "#000000", points: [137,79,137,87,136,89,137,88,135,89,134,89,132,88,133,89,132,87,130,88,131,90,133,91,136,91,138,90,139,88,139,79]},
  {fill: "#000000", points: [143,79,143,91,145,91,145,87,146,86,150,91,152,91,147,85,152,79,150,79,145,85,145,79]},
  {fill: "#000000", points: [156,79,156,91,164,91,164,89,158,89,158,79]},
  {fill: "#000000", points: [169,79,169,91,171,91,171,83,174,89,175,89,178,83,178,91,180,91,180,79,178,79,174,87,175,87,171,79]},
  {fill: "#000000", points: [182,79,182,91,184,91,184,83,189,91,191,91,191,79,189,79,189,87,184,79]},
  {fill: "#000000", points: [0,98,0,110,2,110,2,100,5,100,6,101,6,103,5,104,2,104,2,106,5,106,7,105,8,103,8,101,7,99,5,98]},
  {fill: "#000000", points: [19,109,22,112,24,111,21,108]},
  {fill: "#000000", points: [39,101,39,102,40,104,42,105,44,105,45,106,45,107,47,107,47,106,46,104,44,103,42,103,41,102,41,101]},
  {fill: "#000000", points: [30,105,33,110,35,110,32,105]},
  {fill: "#000000", points: [52,98,52,100,56,100,56,110,58,110,58,100,62,100,62,98]},
  {fill: "#000000", points: [65,98,65,107,67,107,67,98]},
  {fill: "#000000", points: [78,98,82,110,84,110,88,98,86,98,83,107,80,98]},
  {fill: "#000000", points: [91,98,94,110,96,110,98,98,96,98,98,110,100,110,103,98,101,98,98,110,100,110,98,98,96,98,94,110,96,110,93,98]},
  {fill: "#000000", points: [104,98,112,110,114,110,106,98]},
  {fill: "#000000", points: [114,98,106,110,104,110,112,98]},
  {fill: "#000000", points: [117,98,121,105,121,110,123,110,123,105,127,98,125,98,122,103,119,98]},
  {fill: "#000000", points: [130,98,138,98,138,100,132,108,138,108,138,110,130,110,130,108,136,100,130,100]},
  {fill: "#000000", points: [121,193,119,194,118,195,117,197,117,201,118,203,119,204,121,205,125,205,125,204,121,204,119,203,118,201,118,197,119,195,121,194,125,194,127,195,128,197,128,201,127,203,125,204,125,205,127,204,128,203,129,201,129,197,128,195,127,194,125,193]},
  {fill: "#000000", points: [101,89,101,85,97,85,97,87,99,87,99,89]},
  {fill: "#000000", points: [43,79,41,80,40,81,39,83,39,87,40,89,41,90,43,91,46,91,48,90,49,89,47,88,45,89,44,89,42,88,41,86,41,84,42,82,44,81,45,81,47,82,49,81,48,80,46,79]},
  {fill: "#000000", points: [143,117,143,129,145,129,145,127,146,126,148,129,150,129,147,125,150,121,148,121,145,125,145,117]},
  {fill: "#000000", points: [106,124,107,123,108,123,109,124,109,129,111,129,111,124,110,122,108,121,107,121,105,122]},
  {fill: "#000000", points: [117,121,119,121,119,129,117,129]},
  {fill: "#000000", points: [117,117,119,117,119,119,117,119]},
  {fill: "#000000", points: [134,121,134,129,133,131,131,132,130,132,130,130,131,130,132,129,132,121]},
  {fill: "#000000", points: [132,117,134,117,134,119,132,119]},
  {fill: "#000000", points: [156,117,158,117,158,129,156,129]},
  {fill: "#000000", points: [28,143,29,142,30,142,31,143,33,142,32,141,30,140,29,140,27,141]},
  {fill: "#000000", points: [43,148,45,147,46,145,45,144,43,143,42,143,41,142,41,143,42,142,43,142,45,143,46,142,45,141,43,140,42,140,40,141,39,143,40,144,42,145,43,145,44,146,44,145,43,146,42,146,40,145,39,146,40,147,42,148]},
  {fill: "#000000", points: [53,136,53,145,54,147,56,148,57,148,57,146,56,146,55,145,55,136]},
  {fill: "#000000", points: [65,140,65,145,66,147,68,148,69,148,71,147,70,147,70,148,72,148,72,140,70,140,70,145,69,146,68,146,67,145,67,140]},
  {fill: "#000000", points: [78,140,81,148,83,148,86,140,84,140,82,145,80,140]},
  {fill: "#000000", points: [104,140,106,140,112,148,110,148]},
  {fill: "#000000", points: [112,140,110,140,104,148,106,148]},
  {fill: "#000000", points: [126,140,122,148,121,150,119,151,118,151,118,149,119,149,120,148,124,140]},
  {fill: "#000000", points: [117,140,121,148,122,146,119,140]},
  {fill: "#000000", points: [130,140,137,140,137,142,133,146,137,146,137,148,130,148,130,146,134,142,130,142]},
  {fill: "#000000", points: [3,60,1,61,0,63,2,63,3,62,5,62,6,63,8,63,7,61,5,60]},
  {fill: "#000000", points: [45,63,45,64,44,65,42,65,42,67,44,67,45,68,45,69,47,69,47,68,46,66,47,64,47,63]},
  {fill: "#000000", points: [16,60,13,62,13,64,16,62,16,70,13,70,13,72,21,72,21,70,18,70,18,60]},
  {fill: "#000000", points: [57,60,52,67,52,69,60,69,60,67,54,67,57,63,57,72,59,72,59,60]},
  {fill: "#000000", points: [65,60,65,67,67,65,67,62,73,62,73,60]},
  {fill: "#000000", points: [91,60,91,62,97,62,93,72,95,72,99,62,99,60]},
  {fill: "#000000", points: [104,63,104,64,106,67,106,65,104,68,104,69,106,69,106,68,107,67,109,67,110,68,110,69,112,69,112,68,110,65,110,67,112,64,112,63,110,63,110,64,109,65,107,65,106,64,106,63]},
  {fill: "#000000", points: [117,63,117,65,118,67,120,68,122,68,124,67,123,67,123,69,125,69,125,63,123,63,123,65,122,66,120,66,119,65,119,63]},
  {fill: "#000000", points: [91,140,94,148,96,148,97,144,98,148,100,148,103,140,101,140,98,148,100,148,98,140,96,140,94,148,96,148,93,140]},
  {fill: "#000000", points: [13,51,15,51,15,53,13,53]},
  {fill: "#000000", points: [13,41,15,41,15,49,13,49]},
  {fill: "#000000", points: [26,41,28,41,28,45,26,45]},
  {fill: "#000000", points: [29,41,31,41,31,45,29,45]},
  {fill: "#000000", points: [43,41,45,41,43,53,41,53]},
  {fill: "#000000", points: [47,41,49,41,47,53,45,53]},
  {fill: "#000000", points: [39,48,50,48,50,50,39,50]},
  {fill: "#000000", points: [40,44,51,44,51,46,40,46]},
  {fill: "#000000", points: [72,41,74,41,67,53,65,53]},
  {fill: "#000000", points: [83,41,81,42,80,44,81,46,86,53,88,53,83,46,82,44,83,43,84,44,83,45,79,47,78,49,78,50,79,52,81,53,83,53,85,52,86,51,88,47,86,47,85,49,83,51,81,51,80,50,80,49,81,48,85,46,86,44,85,42]},
  {fill: "#000000", points: [91,41,93,41,93,45,91,45]},
  {fill: "#000000", points: [109,40,107,43,106,46,106,50,107,53,109,56,107,56,105,53,104,50,104,46,105,43,107,40]},
  {fill: "#000000", points: [169,46,174,46,174,48,169,48]},
  {fill: "#000000", points: [156,55,158,55,159,53,159,51,157,51,157,53]},
  {fill: "#000000", points: [182,51,184,51,184,53,182,53]},
  {fill: "#000000", points: [202,40,204,40,197,54,195,54]},
  {fill: "#000000", points: [130,64,132,64,132,66,130,66]},
  {fill: "#000000", points: [130,70,132,70,132,72,130,72]},
  {fill: "#000000", points: [143,74,145,74,146,72,146,70,144,70,144,72]},
  {fill: "#000000", points: [144,64,146,64,146,66,144,66]},
  {fill: "#000000", points: [164,62,156,66,164,70,164,68,160,66,164,64]},
  {fill: "#000000", points: [169,63,177,63,177,65,169,65]},
  {fill: "#000000", points: [169,67,177,67,177,69,169,69]},
  {fill: "#000000", points: [182,62,190,66,182,70,182,68,186,66,182,64]},
  {fill: "#000000", points: [201,63,201,64,200,65,199,65,198,66,198,68,200,68,200,67,202,66,203,64,203,63]},
  {fill: "#000000", points: [198,70,200,70,200,72,198,72]},
  {fill: "#000000", points: [143,97,143,113,148,113,148,111,145,111,145,99,148,99,148,97]},
  {fill: "#000000", points: [174,97,174,113,169,113,169,111,172,111,172,99,169,99,169,97]},
  {fill: "#000000", points: [158,97,156,97,163,111,165,111]},
  {fill: "#000000", points: [186,98,182,104,184,104,186,101,188,104,190,104]},
  {fill: "#000000", points: [195,111,203,111,203,113,195,113]},
  {fill: "#000000", points: [148,135,146,136,145,138,145,140,144,142,145,141,143,142,143,144,145,145,144,144,145,146,145,148,146,150,148,151,149,151,149,149,148,149,147,148,147,146,146,144,145,143,146,142,147,140,147,138,148,137,149,137,149,135]},
  {fill: "#000000", points: [156,135,158,135,158,151,156,151]},
  {fill: "#000000", points: [170,135,172,136,173,138,173,140,174,142,173,141,175,142,175,144,173,145,174,144,173,146,173,148,172,150,170,151,169,151,169,149,170,149,171,148,171,146,172,144,173,143,172,142,171,140,171,138,170,137,169,137,169,135]},
  {fill: "#000000", points: [185,139,183,140,182,142,182,143,184,143,184,142,185,141,186,142,187,144,189,145,191,144,192,142,192,141,190,141,190,142,189,143,188,142,187,140]},
  {fill: "#000000", points: [0,117,2,117,4,120,2,120]},
  {fill: "#000000", points: [5,155,3,156,2,157,1,159,1,163,2,165,3,166,5,167,8,167,10,166,9,164,7,165,6,165,4,164,3,162,3,160,4,158,6,157,7,157,9,158,10,156,8,155]},
  {fill: "#000000", points: [122,195,120,196,119,198,119,200,120,202,122,203,124,203,126,202,127,200,125,200,124,201,122,201,121,200,121,198,122,197,124,197,125,198,127,198,126,196,124,195]},
  {fill: "#000000", points: [190,194,186,194,184,195,183,197,183,201,184,203,186,204,190,204,190,205,186,205,184,204,183,203,182,201,182,197,183,195,184,194,186,193,190,193]},
  {fill: "#000000", points: [190,194,192,195,193,197,193,201,192,203,190,204,190,205,192,204,193,203,194,201,194,197,193,195,192,194,190,193]},
  {fill: "#000000", points: [185,195,185,203,187,203,187,197,189,197,189,199,187,199,187,201,189,201,188,200,189,203,191,203,190,200,191,199,191,197,189,195]},
  {fill: "#000000", points: [198,250,196,251,195,253,195,262,197,262,197,253,198,252,199,252,200,253,200,254,199,255,199,256,201,258,201,259,200,260,198,260,198,262,200,262,202,261,203,260,203,258,201,256,201,255,202,254,202,253,201,251,199,250]},
  {fill: "#000000", points: [13,197,15,197,15,195,13,195]},
  {fill: "#000000", points: [13,207,15,207,15,199,13,199]},
  {fill: "#000000", points: [29,196,27,197,26,199,26,201,27,203,29,204,30,204,32,203,33,201,31,201,30,202,29,202,28,201,28,199,29,198,30,198,31,199,33,199,32,197,30,196]},
  {fill: "#000000", points: [53,195,52,196,53,197,52,199,53,201,52,202,53,203,54,202,56,203,57,201,55,201,54,200,54,198,55,197,57,197,58,198,58,200,57,201,56,203,58,202,59,203,60,202,59,201,60,199,59,197,60,196,59,195,58,196,56,195,54,196]},
  {fill: "#000000", points: [66,199,74,199,74,200,66,200]},
  {fill: "#000000", points: [66,201,74,201,74,202,66,202]},
  {fill: "#000000", points: [78,201,80,201,80,208,78,208]},
  {fill: "#000000", points: [78,192,80,192,80,199,78,199]},
  {fill: "#000000", points: [104,195,104,193,106,193,106,195]},
  {fill: "#000000", points: [108,195,108,193,110,193,110,195]},
  {fill: "#000000", points: [146,197,143,200,146,203,147,202,145,200,147,198]},
  {fill: "#000000", points: [149,197,146,200,149,203,150,202,148,200,150,198]},
  {fill: "#000000", points: [156,198,156,200,162,200,162,203,164,203,164,198]},
  {fill: "#000000", points: [195,193,203,193,203,195,195,195]},
  {fill: "#000000", points: [16,213,16,221,18,221,18,213]},
  {fill: "#000000", points: [13,222,21,222,21,224,13,224]},
  {fill: "#000000", points: [56,212,54,212,52,215,54,215]},
  {fill: "#000000", points: [65,221,65,227,67,227,67,223]},
  {fill: "#000000", points: [91,219,93,219,93,221,91,221]},
  {fill: "#000000", points: [105,224,106,224,107,225,107,226,106,227,104,227,104,226,105,226,106,225,106,226,105,225]},
  {fill: "#000000", points: [147,216,150,219,147,222,146,221,148,219,146,217]},
  {fill: "#000000", points: [144,216,147,219,144,222,143,221,145,219,143,217]},
  {fill: "#000000", points: [177,212,179,212,172,224,170,224]},
  {fill: "#000000", points: [179,224,179,223,177,223,179,221,179,220,178,219,176,219,176,220,178,220,178,221,176,223,176,224]},
  {fill: "#000000", points: [164,212,166,212,159,224,157,224]},
  {fill: "#000000", points: [158,212,157,213,157,214,158,213,158,216,157,216,157,217,160,217,160,216,159,216,159,212]},
  {fill: "#000000", points: [190,212,192,212,185,224,183,224]},
  {fill: "#000000", points: [198,218,198,219,196,220,195,222,195,223,196,225,198,226,200,226,202,225,203,223,201,223,200,224,198,224,197,223,197,222,198,221,199,221,200,220,200,218]},
  {fill: "#000000", points: [200,216,198,216,198,214,200,214]},
  {fill: "#000000", points: [83,231,78,243,80,243,85,231,84,233,84,238,82,238,81,240,84,240,84,243,90,243,90,241,86,241,86,238,89,238,89,236,86,236,86,233,90,233,90,231]},
  {fill: "#000000", points: [1,250,1,262,3,262,3,252,5,252,7,253,8,255,8,257,7,259,5,260,3,260,3,262,6,262,8,261,9,260,10,258,10,254,9,252,8,251,6,250]},
  {fill: "#000000", points: [0,255,5,255,5,257,0,257]},
  {fill: "#000000", points: [91,253,92,252,99,259,98,260]},
  {fill: "#000000", points: [98,252,99,253,92,260,91,259]},
  {fill: "#000000", points: [200,91,202,91,204,90,205,89,206,87,206,83,205,81,204,80,202,79,199,79,197,80,196,81,195,83,195,87,196,89,197,90,199,91,200,91,200,89,198,88,197,86,197,84,198,82,200,81,201,81,203,82,204,84,204,86,203,88,201,89,200,89]},
  {fill: "#000000", points: [104,262,113,250,115,250,106,262]},
  {fill: "#000000", points: [182,250,182,262,184,262,184,254,187,254,188,255,188,257,187,258,184,258,184,260,187,260,189,259,190,257,190,255,189,253,187,252,184,252,184,250]},
  {fill: "#000000", points: [182,288,182,303,184,303,184,288]},
  {fill: "#000000", points: [81,273,79,274,80,275,82,275,83,276,83,278,82,279,81,279,80,278,80,279,81,278,83,278,83,276,80,276,78,278,78,279,80,281,82,281,84,280,86,281,87,281,89,280,88,279,86,279,85,278,85,276,86,275,87,275,88,276,85,276,85,278,90,278,90,276,89,274,87,273,86,273,84,274,82,273]},
  {fill: "#000000", points: [91,293,99,293,99,295,91,295]},
  {fill: "#000000", points: [94,290,96,290,96,292,94,292]},
  {fill: "#000000", points: [94,296,96,296,96,298,94,298]},
  {fill: "#000000", points: [107,292,105,293,104,295,104,297,105,299,107,300,108,300,108,298,107,298,106,297,106,295,107,294,108,294,109,295,109,297,108,298,108,300,110,299,111,297,111,295,110,293,108,292]},
  {fill: "#000000", points: [104,300,109,292,111,292,106,300]},
  {fill: "#000000", points: [39,198,45,198,45,200,39,200]},
  {fill: "#000000", points: [171,212,170,213,170,214,171,213,171,216,170,216,170,217,173,217,173,216,172,216,172,212]},
  {fill: "#000000", points: [190,219,188,222,188,223,192,223,192,222,189,222,191,219,190,219,190,224,191,224,191,219]},
  {fill: "#000000", points: [183,212,183,213,185,213,185,214,184,214,184,215,185,215,185,216,183,216,183,217,185,217,186,216,186,215,185,214,185,215,186,214,186,213,185,212]},
  {fill: "#000000", points: [133,49,135,49,135,41,133,41]},
  {fill: "#000000", points: [137,48,138,46,131,42,130,44]},
  {fill: "#000000", points: [131,48,130,46,137,42,138,44]},
  {fill: "#000000", points: [143,46,151,46,151,48,143,48]},
  {fill: "#000000", points: [148,43,148,51,146,51,146,43]},
  {fill: "#000000", points: [117,40,119,43,120,46,120,50,119,53,117,56,119,56,121,53,122,50,122,46,121,43,119,40]},
  {fill: "#000000", points: [0,160,0,161,8,161,8,160]},
  {fill: "#000000", points: [0,162,0,163,8,163,8,162]},
  {fill: "#000000", points: [65,193,69,200,69,205,71,205,71,200,75,193,73,193,70,198,67,193]},
  {fill: "#000000", points: [164,219,162,222,162,223,166,223,166,222,163,222,165,219,164,219,164,224,165,224,165,219]},
  {fill: "#000000", points: [13,216,21,216,21,218,13,218]},
  {fill: "#000000", points: [52,140,52,142,57,142,57,140]},
  {fill: "#000000", points: [29,195,29,205,30,205,30,195]},
  {fill: "#000000", points: [55,40,55,54,56,54,56,40]},
  {fill: "#000000", points: [4,81,2,82,1,83,0,85,0,89,1,91,2,92,4,93,8,93,10,92,10,91,5,91,3,90,2,88,2,86,3,84,5,83,7,83,9,84,10,86,10,87,9,88,10,88,9,87,8,85,6,84,4,85,3,87,4,89,6,90,8,89,6,88,5,87,6,86,7,87,6,88,9,90,10,90,12,88,12,85,11,83,10,82,8,81]},
  {fill: "#000000", points: [3,228,5,228,6,230,5,230]},
  {fill: "#000000", points: [20,228,18,228,17,230,18,230]},
  {fill: "#000000", points: [28,230,30,228,32,228,34,230,32,230,31,229,30,230]},
  {fill: "#000000", points: [54,230,54,228,56,228,56,230]},
  {fill: "#000000", points: [58,230,58,228,60,228,60,230]},
  {fill: "#000000", points: [41,229,43,228,45,229,47,228,47,229,45,230,43,229,41,230]},
  {fill: "#000000", points: [95,231,93,232,92,233,91,235,91,239,92,241,93,242,95,243,98,243,100,242,101,241,99,240,97,241,96,241,94,240,93,238,93,236,94,234,96,233,97,233,99,234,101,233,100,232,98,231]},
  {fill: "#000000", points: [96,243,97,243,98,244,98,245,97,246,95,246,95,245,96,245,97,244,97,245,96,244]},
  {fill: "#000000", points: [94,273,92,274,91,276,91,278,92,280,94,281,95,281,97,280,98,278,96,278,95,279,94,279,93,278,93,276,94,275,95,275,96,276,98,276,97,274,95,273]},
  {fill: "#000000", points: [94,281,95,281,96,282,96,283,95,284,93,284,93,283,94,283,95,282,95,283,94,282]},
  {fill: "#000000", points: [112,243,112,241,106,241,106,238,110,238,110,236,106,236,106,233,112,233,112,231,104,231,104,243]},
  {fill: "#000000", points: [125,243,125,241,119,241,119,238,123,238,123,236,119,236,119,233,125,233,125,231,117,231,117,243]},
  {fill: "#000000", points: [138,243,138,241,132,241,132,238,136,238,136,236,132,236,132,233,138,233,138,231,130,231,130,243]},
  {fill: "#000000", points: [151,243,151,241,145,241,145,238,149,238,149,236,145,236,145,233,151,233,151,231,143,231,143,243]},
  {fill: "#000000", points: [156,231,156,233,157,233,157,241,156,241,156,243,160,243,160,241,159,241,159,233,160,233,160,231]},
  {fill: "#000000", points: [169,231,169,233,170,233,170,241,169,241,169,243,173,243,173,241,172,241,172,233,173,233,173,231]},
  {fill: "#000000", points: [183,231,183,233,184,233,184,241,183,241,183,243,187,243,187,241,186,241,186,233,187,233,187,231]},
  {fill: "#000000", points: [196,231,196,233,197,233,197,241,196,241,196,243,200,243,200,241,199,241,199,233,200,233,200,231]},
  {fill: "#000000", points: [106,228,108,228,109,230,108,230]},
  {fill: "#000000", points: [123,228,121,228,120,230,121,230]},
  {fill: "#000000", points: [131,230,133,228,135,228,137,230,135,230,134,229,133,230]},
  {fill: "#000000", points: [144,230,144,228,146,228,146,230]},
  {fill: "#000000", points: [148,230,148,228,150,228,150,230]},
  {fill: "#000000", points: [156,228,158,228,159,230,158,230]},
  {fill: "#000000", points: [173,228,171,228,170,230,171,230]},
  {fill: "#000000", points: [182,230,184,228,186,228,188,230,186,230,185,229,184,230]},
  {fill: "#000000", points: [195,230,195,228,197,228,197,230]},
  {fill: "#000000", points: [199,230,199,228,201,228,201,230]},
  {fill: "#000000", points: [13,250,13,262,15,262,15,254,20,262,22,262,22,250,20,250,20,258,15,250]},
  {fill: "#000000", points: [15,248,17,247,19,248,21,247,21,248,19,249,17,248,15,249]},
  {fill: "#000000", points: [30,247,32,247,33,249,32,249]},
  {fill: "#000000", points: [46,247,44,247,43,249,44,249]},
  {fill: "#000000", points: [54,249,56,247,58,247,60,249,58,249,57,248,56,249]},
  {fill: "#000000", points: [80,249,80,247,82,247,82,249]},
  {fill: "#000000", points: [84,249,84,247,86,247,86,249]},
  {fill: "#000000", points: [67,248,69,247,71,248,73,247,73,248,71,249,69,248,67,249]},
  {fill: "#000000", points: [120,247,122,247,123,249,122,249]},
  {fill: "#000000", points: [136,247,134,247,133,249,134,249]},
  {fill: "#000000", points: [145,249,147,247,149,247,151,249,149,249,148,248,147,249]},
  {fill: "#000000", points: [158,249,158,247,160,247,160,249]},
  {fill: "#000000", points: [162,249,162,247,164,247,164,249]},
  {fill: "#000000", points: [169,250,173,257,173,262,175,262,175,257,179,250,177,250,174,255,171,250]},
  {fill: "#000000", points: [176,247,174,247,173,249,174,249]},
  {fill: "#000000", points: [2,269,4,269,5,271,4,271]},
  {fill: "#000000", points: [18,269,16,269,15,271,16,271]},
  {fill: "#000000", points: [27,271,29,269,31,269,33,271,31,271,30,270,29,271]},
  {fill: "#000000", points: [53,271,53,269,55,269,55,271]},
  {fill: "#000000", points: [57,271,57,269,59,269,59,271]},
  {fill: "#000000", points: [40,270,42,269,44,270,46,269,46,270,44,271,42,270,40,271]},
  {fill: "#000000", points: [107,273,105,274,104,276,104,278,105,280,107,281,108,281,110,280,109,279,107,279,106,278,106,276,107,275,108,275,109,276,106,276,106,278,111,278,111,276,110,274,108,273]},
  {fill: "#000000", points: [120,273,118,274,117,276,117,278,118,280,120,281,121,281,123,280,122,279,120,279,119,278,119,276,120,275,121,275,122,276,119,276,119,278,124,278,124,276,123,274,121,273]},
  {fill: "#000000", points: [133,273,131,274,130,276,130,278,131,280,133,281,134,281,136,280,135,279,133,279,132,278,132,276,133,275,134,275,135,276,132,276,132,278,137,278,137,276,136,274,134,273]},
  {fill: "#000000", points: [146,273,144,274,143,276,143,278,144,280,146,281,147,281,149,280,148,279,146,279,145,278,145,276,146,275,147,275,148,276,145,276,145,278,150,278,150,276,149,274,147,273]},
  {fill: "#000000", points: [106,269,108,269,109,271,108,271]},
  {fill: "#000000", points: [122,269,120,269,119,271,120,271]},
  {fill: "#000000", points: [131,271,133,269,135,269,137,271,135,271,134,270,133,271]},
  {fill: "#000000", points: [144,271,144,269,146,269,146,271]},
  {fill: "#000000", points: [148,271,148,269,150,269,150,271]},
  {fill: "#000000", points: [157,273,159,273,159,281,157,281]},
  {fill: "#000000", points: [169,273,171,273,171,281,169,281]},
  {fill: "#000000", points: [184,273,186,273,186,281,184,281]},
  {fill: "#000000", points: [197,273,199,273,199,281,197,281]},
  {fill: "#000000", points: [156,269,158,269,159,271,158,271]},
  {fill: "#000000", points: [172,269,170,269,169,271,170,271]},
  {fill: "#000000", points: [182,271,184,269,186,269,188,271,186,271,185,270,184,271]},
  {fill: "#000000", points: [195,271,195,269,197,269,197,271]},
  {fill: "#000000", points: [199,271,199,269,201,269,201,271]},
  {fill: "#000000", points: [117,292,117,297,118,299,120,300,121,300,123,299,122,299,122,300,124,300,124,292,122,292,122,297,121,298,120,298,119,297,119,292]},
  {fill: "#000000", points: [130,292,130,297,131,299,133,300,134,300,136,299,135,299,135,300,137,300,137,292,135,292,135,297,134,298,133,298,132,297,132,292]},
  {fill: "#000000", points: [143,292,143,297,144,299,146,300,147,300,149,299,148,299,148,300,150,300,150,292,148,292,148,297,147,298,146,298,145,297,145,292]},
  {fill: "#000000", points: [156,292,156,297,157,299,159,300,160,300,162,299,161,299,161,300,163,300,163,292,161,292,161,297,160,298,159,298,158,297,158,292]},
  {fill: "#000000", points: [178,292,174,300,173,302,171,303,170,303,170,301,171,301,172,300,176,292]},
  {fill: "#000000", points: [169,292,173,300,174,298,171,292]},
  {fill: "#000000", points: [204,292,200,300,199,302,197,303,196,303,196,301,197,301,198,300,202,292]},
  {fill: "#000000", points: [195,292,199,300,200,298,197,292]},
  {fill: "#000000", points: [119,288,121,288,122,290,121,290]},
  {fill: "#000000", points: [135,288,133,288,132,290,133,290]},
  {fill: "#000000", points: [144,290,146,288,148,288,150,290,148,290,147,289,146,290]},
  {fill: "#000000", points: [157,290,157,288,159,288,159,290]},
  {fill: "#000000", points: [161,290,161,288,163,288,163,290]},
  {fill: "#000000", points: [175,288,173,288,172,290,173,290]},
  {fill: "#000000", points: [197,290,197,288,199,288,199,290]},
  {fill: "#000000", points: [201,290,201,288,203,288,203,290]},
  {fill: "#000000", points: [29,292,27,293,26,295,26,297,27,299,29,300,30,300,30,298,29,298,28,297,28,295,29,294,30,294,31,295,31,297,30,298,30,300,32,299,33,297,33,295,32,293,30,292]},
  {fill: "#000000", points: [42,292,40,293,39,295,39,297,40,299,42,300,43,300,43,298,42,298,41,297,41,295,42,294,43,294,44,295,44,297,43,298,43,300,45,299,46,297,46,295,45,293,43,292]},
  {fill: "#000000", points: [55,292,53,293,52,295,52,297,53,299,55,300,56,300,56,298,55,298,54,297,54,295,55,294,56,294,57,295,57,297,56,298,56,300,58,299,59,297,59,295,58,293,56,292]},
  {fill: "#000000", points: [68,292,66,293,65,295,65,297,66,299,68,300,69,300,69,298,68,298,67,297,67,295,68,294,69,294,70,295,70,297,69,298,69,300,71,299,72,297,72,295,71,293,69,292]},
  {fill: "#000000", points: [81,292,79,293,78,295,78,297,79,299,81,300,82,300,82,298,81,298,80,297,80,295,81,294,82,294,83,295,83,297,82,298,82,300,84,299,85,297,85,295,84,293,82,292]},
  {fill: "#000000", points: [14,289,16,288,18,289,20,288,20,289,18,290,16,289,14,290]},
  {fill: "#000000", points: [28,288,30,288,31,290,30,290]},
  {fill: "#000000", points: [44,288,42,288,41,290,42,290]},
  {fill: "#000000", points: [53,290,55,288,57,288,59,290,57,290,56,289,55,290]},
  {fill: "#000000", points: [66,289,68,288,70,289,72,288,72,289,70,290,68,289,66,290]},
  {fill: "#000000", points: [79,290,79,288,81,288,81,290]},
  {fill: "#000000", points: [83,290,83,288,85,288,85,290]},
  {fill: "#000000", points: [66,41,65,42,65,44,66,45,67,45,66,43,67,41,65,43,67,42,69,43,67,41,68,43,67,45,69,43,67,44,65,43,67,45,68,45,69,44,69,42,68,41]},
  {fill: "#000000", points: [55,41,53,42,52,44,52,45,53,47,55,48,56,48,57,49,57,50,56,51,55,51,54,50,52,50,53,52,55,53,56,53,58,52,59,50,59,49,58,47,56,46,55,46,54,45,54,44,55,43,56,43,57,44,59,44,58,42,56,41]},
  {fill: "#000000", points: [26,98,26,110,28,110,28,100,31,100,32,101,32,103,31,104,28,104,28,106,31,106,33,105,34,103,34,101,33,99,31,98]},
  {fill: "#000000", points: [95,79,93,80,92,81,91,83,91,87,92,89,93,90,95,91,98,91,100,90,101,89,99,88,97,89,96,89,94,88,93,86,93,84,94,82,96,81,97,81,99,82,101,81,100,80,98,79]},
  {fill: "#000000", points: [16,121,14,122,13,124,13,126,14,128,16,129,17,129,17,127,16,127,15,126,15,124,16,123,17,123,18,124,18,126,17,127,17,129,19,128,20,126,20,124,19,122,17,121]},
  {fill: "#000000", points: [29,121,27,122,26,124,26,126,27,128,29,129,30,129,30,127,29,127,28,126,28,124,29,123,30,123,31,124,31,126,30,127,30,129,32,128,33,126,33,124,32,122,30,121]},
  {fill: "#000000", points: [26,129,28,129,28,117,26,117]},
  {fill: "#000000", points: [55,121,53,122,52,124,52,126,53,128,55,129,56,129,56,127,55,127,54,126,54,124,55,123,56,123,57,124,57,126,56,127,56,129,58,128,59,126,59,124,58,122,56,121]},
  {fill: "#000000", points: [57,129,59,129,59,117,57,117]},
  {fill: "#000000", points: [94,121,92,122,91,124,91,126,92,128,94,129,95,129,95,127,94,127,93,126,93,124,94,123,95,123,96,124,96,126,95,127,95,129,97,128,98,126,98,124,97,122,95,121]},
  {fill: "#000000", points: [104,117,106,117,106,129,104,129]},
  {fill: "#000000", points: [184,124,185,123,186,123,187,124,187,129,189,129,189,124,188,122,186,121,185,121,183,122]},
  {fill: "#000000", points: [182,121,184,121,184,129,182,129]},
  {fill: "#000000", points: [171,124,172,123,173,123,174,124,174,129,176,129,176,124,175,122,173,121,172,121,170,122]},
  {fill: "#000000", points: [169,121,171,121,171,129,169,129]},
  {fill: "#000000", points: [176,124,177,123,178,123,179,124,179,129,181,129,181,124,180,122,178,121,177,121,175,122]},
  {fill: "#000000", points: [26,140,28,140,28,148,26,148]},
  {fill: "#000000", points: [185,292,183,293,182,295,182,297,183,299,185,300,186,300,186,298,185,298,184,297,184,295,185,294,186,294,187,295,187,297,186,298,186,300,188,299,189,297,189,295,188,293,186,292]},
  {fill: "#000000", points: [15,295,16,294,17,294,18,295,18,300,20,300,20,295,19,293,17,292,16,292,14,293]},
  {fill: "#000000", points: [13,292,15,292,15,300,13,300]},
  {fill: "#000000", points: [5,281,7,281,7,273,5,273]},
  {fill: "#000000", points: [3,273,1,274,0,276,0,278,1,280,3,281,4,281,4,279,3,279,2,278,2,276,3,275,4,275,5,276,5,278,4,279,4,281,6,280,7,278,7,276,6,274,4,273]},
  {fill: "#000000", points: [18,281,20,281,20,273,18,273]},
  {fill: "#000000", points: [16,273,14,274,13,276,13,278,14,280,16,281,17,281,17,279,16,279,15,278,15,276,16,275,17,275,18,276,18,278,17,279,17,281,19,280,20,278,20,276,19,274,17,273]},
  {fill: "#000000", points: [31,281,33,281,33,273,31,273]},
  {fill: "#000000", points: [29,273,27,274,26,276,26,278,27,280,29,281,30,281,30,279,29,279,28,278,28,276,29,275,30,275,31,276,31,278,30,279,30,281,32,280,33,278,33,276,32,274,30,273]},
  {fill: "#000000", points: [44,281,46,281,46,273,44,273]},
  {fill: "#000000", points: [42,273,40,274,39,276,39,278,40,280,42,281,43,281,43,279,42,279,41,278,41,276,42,275,43,275,44,276,44,278,43,279,43,281,45,280,46,278,46,276,45,274,43,273]},
  {fill: "#000000", points: [57,281,59,281,59,273,57,273]},
  {fill: "#000000", points: [55,273,53,274,52,276,52,278,53,280,55,281,56,281,56,279,55,279,54,278,54,276,55,275,56,275,57,276,57,278,56,279,56,281,58,280,59,278,59,276,58,274,56,273]},
  {fill: "#000000", points: [70,281,72,281,72,273,70,273]},
  {fill: "#000000", points: [68,273,66,274,65,276,65,278,66,280,68,281,69,281,69,279,68,279,67,278,67,276,68,275,69,275,70,276,70,278,69,279,69,281,71,280,72,278,72,276,71,274,69,273]},
  {fill: "#000000", points: [65,216,65,221,66,223,68,224,69,224,71,223,70,223,70,224,72,224,72,216,70,216,70,221,69,222,68,222,67,221,67,216]},
  {fill: "#000000", points: [3,72,1,71,0,69,2,69,3,70,5,70,6,69,8,69,7,71,5,72]},
  {fill: "#000000", points: [0,63,2,63,2,69,0,69]},
  {fill: "#000000", points: [6,63,8,63,8,69,6,69]},
  {fill: "#000000", points: [29,60,27,61,26,63,28,63,29,62,31,62,32,63,34,63,33,61,31,60]},
  {fill: "#000000", points: [42,60,40,61,39,63,41,63,42,62,44,62,45,63,47,63,46,61,44,60]},
  {fill: "#000000", points: [42,72,40,71,39,69,41,69,42,70,44,70,45,69,47,69,46,71,44,72]},
  {fill: "#000000", points: [68,72,66,71,65,69,67,69,68,70,70,70,71,69,73,69,72,71,70,72]},
  {fill: "#000000", points: [68,64,66,65,65,67,67,67,68,66,70,66,71,67,71,69,73,69,73,67,72,65,70,64]},
  {fill: "#000000", points: [81,64,79,65,78,67,80,67,81,66,83,66,84,67,84,69,86,69,86,67,85,65,83,64]},
  {fill: "#000000", points: [81,72,79,71,78,69,80,69,81,70,83,70,84,69,86,69,85,71,83,72]},
  {fill: "#000000", points: [81,60,79,61,78,63,80,63,81,62,83,62,84,63,86,63,85,61,83,60]},
  {fill: "#000000", points: [78,63,78,69,80,69,80,63]},
  {fill: "#000000", points: [107,60,105,61,104,63,106,63,107,62,109,62,110,63,112,63,111,61,109,60]},
  {fill: "#000000", points: [107,72,105,71,104,69,106,69,107,70,109,70,110,69,112,69,111,71,109,72]},
  {fill: "#000000", points: [120,72,118,71,117,69,119,69,120,70,122,70,123,69,125,69,124,71,122,72]},
  {fill: "#000000", points: [120,60,118,61,117,63,119,63,120,62,122,62,123,63,125,63,124,61,122,60]},
  {fill: "#000000", points: [42,98,40,99,39,101,41,101,42,100,44,100,45,101,47,101,46,99,44,98]},
  {fill: "#000000", points: [42,110,40,109,39,107,41,107,42,108,44,108,45,107,47,107,46,109,44,110]},
  {fill: "#000000", points: [198,60,196,61,195,63,197,63,198,62,200,62,201,63,203,63,202,61,200,60]},
  {fill: "#000000", points: [72,98,72,106,71,108,72,107,70,108,69,108,67,107,68,108,67,106,65,107,66,109,68,110,71,110,73,109,74,107,74,98]},
  {fill: "#000000", points: [117,250,117,259,119,258,119,250]},
  {fill: "#000000", points: [124,250,124,258,123,260,124,259,122,260,121,260,119,259,120,260,119,258,117,259,118,261,120,262,123,262,125,261,126,259,126,250]},
  {fill: "#000000", points: [130,250,130,259,132,258,132,250]},
  {fill: "#000000", points: [137,250,137,258,136,260,137,259,135,260,134,260,132,259,133,260,132,258,130,259,131,261,133,262,136,262,138,261,139,259,139,250]},
  {fill: "#000000", points: [143,250,143,259,145,258,145,250]},
  {fill: "#000000", points: [150,250,150,258,149,260,150,259,148,260,147,260,145,259,146,260,145,258,143,259,144,261,146,262,149,262,151,261,152,259,152,250]},
  {fill: "#000000", points: [156,250,156,259,158,258,158,250]},
  {fill: "#000000", points: [163,250,163,258,162,260,163,259,161,260,160,260,158,259,159,260,158,258,156,259,157,261,159,262,162,262,164,261,165,259,165,250]},
  {fill: "#000000", points: [3,140,1,141,0,143,0,145,1,147,3,148,4,148,4,146,3,146,2,145,2,143,3,142,4,142,5,143,5,145,4,146,4,148,6,147,7,145,7,143,6,141,4,140]},
  {fill: "#000000", points: [16,140,14,141,13,143,13,145,14,147,16,148,17,148,17,146,16,146,15,145,15,143,16,142,17,142,18,143,18,145,17,146,17,148,19,147,20,145,20,143,19,141,17,140]},
  {fill: "#000000", points: [0,140,0,151,2,151,2,140]},
  {fill: "#000000", points: [18,140,18,151,20,151,20,140]},
  {fill: "#000000", points: [78,121,78,123,83,123,83,121]},
  {fill: "#000000", points: [71,49,70,50,70,52,71,53,72,53,71,51,72,49,70,51,72,50,74,51,72,49,73,51,72,53,74,51,72,52,70,51,72,53,73,53,74,52,74,50,73,49]},
  {fill: "#000000", points: [1,212,0,213,0,215,1,216,2,216,1,214,2,212,0,214,2,213,4,214,2,212,3,214,2,216,4,214,2,215,0,214,2,216,3,216,4,215,4,213,3,212]},
  {fill: "#000000", points: [69,228,68,229,68,231,69,232,70,232,69,230,70,228,68,230,70,229,72,230,70,228,71,230,70,232,72,230,70,231,68,230,70,232,71,232,72,231,72,229,71,228]},
  {fill: "#000000", points: [68,268,67,269,67,271,68,272,69,272,68,270,69,268,67,270,69,269,71,270,69,268,70,270,69,272,71,270,69,271,67,270,69,272,70,272,71,271,71,269,70,268]},
  {fill: "#000000", points: [4,231,0,243,2,243,5,234,7,238,3,238,2,240,8,240,5,234,8,243,10,243,6,231]},
  {fill: "#000000", points: [17,231,13,243,15,243,18,234,20,238,16,238,15,240,21,240,18,234,21,243,23,243,19,231]},
  {fill: "#000000", points: [30,231,26,243,28,243,31,234,33,238,29,238,28,240,34,240,31,234,34,243,36,243,32,231]},
  {fill: "#000000", points: [43,231,39,243,41,243,44,234,46,238,42,238,41,240,47,240,44,234,47,243,49,243,45,231]},
  {fill: "#000000", points: [56,231,52,243,54,243,57,234,59,238,55,238,54,240,60,240,57,234,60,243,62,243,58,231]},
  {fill: "#000000", points: [69,231,65,243,67,243,70,234,72,238,68,238,67,240,73,240,70,234,73,243,75,243,71,231]},
  {fill: "#000000", points: [31,262,33,262,35,261,36,260,37,258,37,254,36,252,35,251,33,250,30,250,28,251,27,252,26,254,26,258,27,260,28,261,30,262,31,262,31,260,29,259,28,257,28,255,29,253,31,252,32,252,34,253,35,255,35,257,34,259,32,260,31,260]},
  {fill: "#000000", points: [44,262,46,262,48,261,49,260,50,258,50,254,49,252,48,251,46,250,43,250,41,251,40,252,39,254,39,258,40,260,41,261,43,262,44,262,44,260,42,259,41,257,41,255,42,253,44,252,45,252,47,253,48,255,48,257,47,259,45,260,44,260]},
  {fill: "#000000", points: [57,262,59,262,61,261,62,260,63,258,63,254,62,252,61,251,59,250,56,250,54,251,53,252,52,254,52,258,53,260,54,261,56,262,57,262,57,260,55,259,54,257,54,255,55,253,57,252,58,252,60,253,61,255,61,257,60,259,58,260,57,260]},
  {fill: "#000000", points: [70,262,72,262,74,261,75,260,76,258,76,254,75,252,74,251,72,250,69,250,67,251,66,252,65,254,65,258,66,260,67,261,69,262,70,262,70,260,68,259,67,257,67,255,68,253,70,252,71,252,73,253,74,255,74,257,73,259,71,260,70,260]},
  {fill: "#000000", points: [83,262,85,262,87,261,88,260,89,258,89,254,88,252,87,251,85,250,82,250,80,251,79,252,78,254,78,258,79,260,80,261,82,262,83,262,83,260,81,259,80,257,80,255,81,253,83,252,84,252,86,253,87,255,87,257,86,259,84,260,83,260]},
  {fill: "#000000", points: [109,262,111,262,113,261,114,260,115,258,115,254,114,252,113,251,111,250,108,250,106,251,105,252,104,254,104,258,105,260,106,261,108,262,109,262,109,260,107,259,106,257,106,255,107,253,109,252,110,252,112,253,113,255,113,257,112,259,110,260,109,260]},
  {fill: "#000000", points: [18,110,20,110,22,109,23,108,24,106,24,102,23,100,22,99,20,98,17,98,15,99,14,100,13,102,13,106,14,108,15,109,17,110,18,110,18,108,16,107,15,105,15,103,16,101,18,100,19,100,21,101,22,103,22,105,21,107,19,108,18,108]},
  {fill: "#000000", points: [3,292,1,293,0,295,0,297,1,299,3,300,4,300,4,298,3,298,2,297,2,295,3,294,4,294,5,295,5,297,4,298,4,300,6,299,7,297,7,295,6,293,4,292]},
  {fill: "#000000", points: [7,295,7,294,6,291,4,289,2,288,1,289,3,290,4,292]},
  {fill: "#000000", points: [5,288,6,289,2,292,1,291]}
];

var charWidth=13;
var charHeight=19;

var charData = [];
var firstChar=255, lastChar=0;
var maxPolyLen = 0;
polyImg.forEach(function(poly) {
  let buf = poly.points;
  var minx=1000,maxx=-1,miny=1000,maxy=-1;
  var poly = [];
  for (var i=0;i<buf.length;i+=2) {
    var x = buf[i];
    var y = buf[i+1];
    if (x<minx) minx=x;
    if (y<miny) miny=y;
    if (x>maxx) maxx=x;
    if (y>maxy) maxy=y;
    poly.push((x%charWidth)+(y%charHeight)*charWidth);
  }
  if (poly.length > maxPolyLen)
    maxPolyLen = poly.length;
  var cx = Math.floor(minx/charWidth);
  var cy = Math.floor(miny/charHeight);
  var dx = Math.floor(maxx/charWidth);
  var dy = Math.floor(maxy/charHeight);
  var charNumber = cx + (cy*16);
  if (charNumber > lastChar) lastChar = charNumber;
  if (charNumber < firstChar) firstChar = charNumber;

  if (cx!=dx || cy!=dy) console.log(`Char near position ${charNumber} (${String.fromCharCode(charNumber)}) straddles boundary!`);

  if (charData[charNumber]===undefined)
    charData[charNumber] = [];
  charData[charNumber].push(poly);
});

function normalizePoly(poly) {
  var min = Math.min(...poly);
  while (poly[0] != min) {
    poly.push(poly.shift());
  }
  if (poly[1] > poly[poly.length-1]) {
    poly.reverse();
    poly.unshift(poly.pop());
  }
}

var uniquePolys = [];
var charPolyIndices = charData.map(charPolys => charPolys.map(poly => {
  normalizePoly(poly);
  var i = uniquePolys.findIndex(p => JSON.stringify(poly) == JSON.stringify(p));
  if (i == -1) i = uniquePolys.push(poly) - 1;
  return i;
}));

if (uniquePolys.length > 256) console.log(`More than 256 unique polys!`);

function range(min, max) {
  var r = [];
  for (let n = min; n <= max; ++n) {
    r.push(n);
  }
  return r;
}

var vector_font_c = `/*
 * This file is part of Espruino, a JavaScript interpreter for Microcontrollers
 *
 * Copyright (C) 2020 Gordon Williams <gw@pur3.co.uk>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * ----------------------------------------------------------------------------
 * Machine generated vector font header (by build_vector_font.sh)
 * ----------------------------------------------------------------------------
 */

#ifndef NO_VECTOR_FONT
#include "graphics.h"

const uint8_t vfFirstChar = ${firstChar};
const uint8_t vfLastChar = ${lastChar};
#define VF_CHAR_WIDTH ${charWidth}
#define VF_SCALE 16
#define VF_OFFSET_Y (-2)
#define VF_CHAR_SPACING 1
static const uint8_t vfPolyVerts[] IN_FLASH_MEMORY = {
  ${uniquePolys.map(p => p.join(",")).join(",\n  ")}
};
static const uint8_t vfPolyLengths[] IN_FLASH_MEMORY = {
  ${uniquePolys.map(p => p.length).join(",")}
};
static const uint8_t vfCharPolys[] IN_FLASH_MEMORY = {
  ${
    range(firstChar, lastChar)
      .map(c => charPolyIndices[c])
      .filter(c => c != undefined)
      .map(c => c.join(","))
      .join(",\n  ")
  }
};
static const uint8_t vfCharLengths[] IN_FLASH_MEMORY = {
  ${
    range(firstChar, lastChar)
      .map(c => charPolyIndices[c] ? charPolyIndices[c].length : 0)
      .join(",")
  }
};

static const uint8_t *vfGetPolyPtr(unsigned char index, int *polyLen) {
  if (index >= sizeof(vfPolyLengths)) return NULL;

  *polyLen = vfPolyLengths[index];
  const uint8_t *ptr = vfPolyVerts;
  for (unsigned char i=0; i < index; ++i) {
    ptr += vfPolyLengths[i];
  }
  return ptr;
}

static const uint8_t *vfGetCharPtr(char sch, int *charLen) {
  unsigned char ch = (unsigned char)sch;
  if (ch<vfFirstChar || ch>vfLastChar) return NULL;
  ch = (unsigned char)(ch - vfFirstChar);

  const uint8_t *ptr = vfCharPolys;
  for (unsigned char i=0; i < ch; ++i) {
    ptr += vfCharLengths[i];
  }
  *charLen = vfCharLengths[ch];
  return ptr;
}

// prints character, returns width
unsigned int vfDrawCharPtr(JsGraphics *gfx, int x1, int y1, int size, const uint8_t *charPtr, int charLen) {
  x1 = (x1<<4) - 8;
  y1 = (y1<<4) - 8;
  int w = 0;
  for (int i = 0; i < charLen; ++i) {
    short poly[${maxPolyLen*2}];
    int polyLen;
    const uint8_t *p = vfGetPolyPtr(charPtr[i], &polyLen);
    for (int j = 0; j < polyLen; ++j) {
      uint8_t vertex = p[j];
      int vx = vertex % VF_CHAR_WIDTH;
      int vy = vertex / VF_CHAR_WIDTH;
      if (vx>w) w=vx;
      poly[j*2  ] = (short)(x1 + vx*size*16/VF_SCALE);
      poly[j*2+1] = (short)(y1 + (vy+VF_OFFSET_Y)*size*16/VF_SCALE);
    }
    graphicsFillPoly(gfx, polyLen, poly);
  }
  return (unsigned int)(((w+1+VF_CHAR_SPACING)*size*16/VF_SCALE+7)>>4);
}

// returns the width of a character
unsigned int graphicsVectorCharWidth(JsGraphics *gfx, unsigned int size, char ch) {
  NOT_USED(gfx);
  int charLen;
  const uint8_t *charPtr = vfGetCharPtr(ch, &charLen);
  if (!charPtr) return (unsigned int)(size/2);
  int w = 0;
  for (int i = 0; i < charLen; ++i) {
    int polyLen;
    const uint8_t *p = vfGetPolyPtr(charPtr[i], &polyLen);
    for (int j = 0; j < polyLen; ++j) {
      uint8_t vertex = p[j];
      int vx = vertex % VF_CHAR_WIDTH;
      if (vx>w) w=vx;
    }
  }
  return ((unsigned int)(w+1+VF_CHAR_SPACING)*size*16/VF_SCALE+7)>>4;
}

// prints character, returns width
unsigned int graphicsFillVectorChar(JsGraphics *gfx, int x1, int y1, int size, char ch) {
  int charLen;
  const uint8_t *charPtr = vfGetCharPtr(ch, &charLen);
  if (!charPtr) return (unsigned int)(size/2);
  return vfDrawCharPtr(gfx, x1, y1, size, charPtr, charLen);
}

#endif
`;

var vector_font_h = `/*
 * This file is part of Espruino, a JavaScript interpreter for Microcontrollers
 *
 * Copyright (C) 2020 Gordon Williams <gw@pur3.co.uk>
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * ----------------------------------------------------------------------------
 * Machine generated vector font header (by build_vector_font.sh)
 * ----------------------------------------------------------------------------
 */

#ifndef NO_VECTOR_FONT
#include "graphics.h"

// returns the width of a character
unsigned int graphicsVectorCharWidth(JsGraphics *gfx, unsigned int size, char ch);
// prints character, returns width
unsigned int graphicsFillVectorChar(JsGraphics *gfx, int x1, int y1, int size, char ch);
#endif
`;


require("fs").writeFileSync(__dirname + "/../vector_font.c", vector_font_c);
require("fs").writeFileSync(__dirname + "/../vector_font.h", vector_font_h);
